﻿using System.Collections.Generic;
using Aluetjen.EmailService.Domain.Gateways;
using Aluetjen.EmailService.Domain.Models.Message;
using Aluetjen.EmailService.Domain.Models.Pipeline;
using Aluetjen.EmailService.Domain.Tests.Services;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Aluetjen.EmailService.Domain.SystemTests.Services
{
    [TestClass]
    public class DispatchServiceTests : DispatchServiceTestsBase
    {
        [TestMethod]
        public void Dispatch_Should_Send_To_Smtp_Server()
        {
            SetUpMocks();

            var gateway = new Gateway
            {
                Name = "SmtpGateway",
                DispatchToGateway = true,
                IgnoreFailure = false
            };

            AddGateway(gateway);
            AddGatewayImpl(gateway.Name, new SmtpGateway());

            SetUpRepository();

            var mail = new MailMessage
                           {
                               To = new List<MailAddress> { new MailAddress{ Address = "admin@luetjen.ie"}},
                               From = new MailAddress { Address = "luetjen@gmail.com" },
                               Subject = "System test",
                               Body = "Hello World! From System Test"
                           };

            var service = GetInstance();
            service.ProcessMessage(mail);
        }

        [TestMethod]
        public void Dispatch_Should_Send_To_FileShare()
        {
            SetUpMocks();

            var gateway = new Gateway
            {
                Name = "TestGateway",
                DispatchToGateway = true,
                IgnoreFailure = false
            };

            AddGateway(gateway);
            AddGatewayImpl(gateway.Name, new FileShareGateway("."));

            SetUpRepository();

            var mail = new MailMessage
            {
                To = new List<MailAddress> { new MailAddress { Address = "admin@luetjen.ie" } },
                From = new MailAddress { Address = "luetjen@gmail.com" },
                Subject = "System test",
                Body = "Hello World! From System Test"
            };

            var service = GetInstance();
            service.ProcessMessage(mail);
        }
    }
}
